package com.ideal.manage.esms.compoment;

import com.ideal.manage.esms.service.IntegrationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

@Component
public class IntegrationTask {
    private Logger LOG = LoggerFactory.getLogger(IntegrationTask.class);

    @Autowired
    private IntegrationService integrationService;
    @Value("${config.task.integration.enable}")
    private Boolean integrationTaskEnable;


    //10秒一次
    @Scheduled(fixedDelay = 10000)
    public void scan() {
        if(integrationTaskEnable){
            LocalDateTime now = LocalDateTime.now();
            long last = now.minusMinutes(15).toInstant(ZoneOffset.of("+8")).toEpochMilli();
            integrationService.autoCal(last);
        }else {
            LOG.debug("计算积分汇总任务暂停");
        }
    }
}
